<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>封装</title>
</head>
<body>
<p>封装的目的是将信息隐藏。</p>
<script>
    var myObject = (function () {
        var __name = 'sven';  // 私有 private
        return {
            getName: function () {
                return __name
            }
        }
    })()
    var myObject2 = function () {
        let __name = 'sven2'; // 私有 private
        return {
            getName: function () {
                return __name
            }
        }
    }
</script>
<p>假如有个需求: 飞机大战网页游戏 某种飞机拥有分身技能 当使用分身技能的时候 要在页面创建一些一模一样的飞机</p>
<p>如果使用原型模式</p>
<script>
    let Plane = function () {
        this.blood = 100;
        this.attackLevel = 1;
        this.defenseLevel  = 1;
    }
    let plane = new Plane()
    plane.blood = 100;
    plane.attackLevel = 10;
    plane.defenseLevel = 5;
    let clonePlane = Object.create(plane)
    console.log(clonePlane)
    // 兼容
    Object.create = Object.create || function(obj) {
        let F = function () {}
        F.prototype = obj
        return new F()
    }

</script>

</body>
</html>